/**
* @file message_code.h
* @brief 消息吗
* @author chenxiaole
* @version 1.0.0
* @date 2018-03-27
*/
#ifndef GAME_MESSAGE_CODE_H_
#define GAME_MESSAGE_CODE_H_


#include "Player.h"


#include "../share/string_common.h"
#include "../share/MessageDef.h"
#include "GameServer.h"
#include "team_mgr.h"


class CMsgCode
{
 public:
    static void SendMsgCodeToPlayer( Player& player, int32_t msg_code )
    {
        if( msg_code == 0 )
        {
            return;
        }
		if ( player.GetSocketId() == 0 )
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(player.GetSocketId(), m_send, common_msg_notify);
    }

	static void SendMsgCodeToPlayer(Player& player, std::string& msg)
	{
		if (player.GetSocketId() == 0)
		{
			return;
		}
		GameServer::GetInstance().send_by_uid(player.GetSocketId(), msg, common_msg_notify);
	}

    template< typename T1 >
    static void SendMsgCodeToPlayer( Player& player, int32_t msg_code, const T1& t1 )
    {
		if (msg_code == 0)
		{
			return;
		}
		if (player.GetSocketId() == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(player.GetSocketId(), m_send, common_msg_notify);
    }

    template< typename T1, typename T2 >
    static void SendMsgCodeToPlayer( Player& player, int32_t msg_code, const T1& t1, const T2& t2 )
    {
		if (msg_code == 0)
		{
			return;
		}
		if (player.GetSocketId() == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(player.GetSocketId(), m_send, common_msg_notify);
    }

    template< typename T1, typename T2, typename T3 >
    static void SendMsgCodeToPlayer( Player& player, int32_t msg_code, const T1& t1, const T2& t2, const T3& t3 )
    {
		if (msg_code == 0)
		{
			return;
		}
		if (player.GetSocketId() == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(player.GetSocketId(), m_send, common_msg_notify);
    }

    template< typename T1, typename T2, typename T3, typename T4 >
    static void SendMsgCodeToPlayer( Player& player, int32_t msg_code, const T1& t1, const T2& t2, const T3& t3, const T4& t4 )
    {
		if (msg_code == 0)
		{
			return;
		}
		if (player.GetSocketId() == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);
		send_to_player["param3"] = ::common::ToString(t4);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(player.GetSocketId(), m_send, common_msg_notify);
    }

    template< typename T1, typename T2, typename T3, typename T4, typename T5 >
    static void SendMsgCodeToPlayer( Player& player, int32_t msg_code, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5 )
    {
		if (msg_code == 0)
		{
			return;
		}
		if (player.GetSocketId() == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);
		send_to_player["param3"] = ::common::ToString(t4);
		send_to_player["param4"] = ::common::ToString(t5);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(player.GetSocketId(), m_send, common_msg_notify);
    }

	static void SendMsgCodeToPlayer(uint32_t socket_id, int32_t msg_code)
	{
		if (msg_code == 0)
		{
			return;
		}
		if (socket_id == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(socket_id, m_send, common_msg_notify);
	}

	static void SendMsgCodeToPlayer(uint32_t socket_id, std::string& msg)
	{
		if (socket_id == 0)
		{
			return;
		}
		
		GameServer::GetInstance().send_by_uid(socket_id, msg, common_msg_notify);
	}

	template< typename T1 >
	static void SendMsgCodeToPlayer(uint32_t socket_id, int32_t msg_code, const T1& t1)
	{
		if (msg_code == 0)
		{
			return;
		}
		if (socket_id == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(socket_id, m_send, common_msg_notify);
	}

	template< typename T1, typename T2 >
	static void SendMsgCodeToPlayer(uint32_t socket_id, int32_t msg_code, const T1& t1, const T2& t2)
	{
		if (msg_code == 0)
		{
			return;
		}
		if (socket_id == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(socket_id, m_send, common_msg_notify);
	}

	template< typename T1, typename T2, typename T3 >
	static void SendMsgCodeToPlayer(uint32_t socket_id, int32_t msg_code, const T1& t1, const T2& t2, const T3& t3)
	{
		if (msg_code == 0)
		{
			return;
		}
		if (socket_id == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(socket_id, m_send, common_msg_notify);
	}

	template< typename T1, typename T2, typename T3, typename T4 >
	static void SendMsgCodeToPlayer(uint32_t socket_id, int32_t msg_code, const T1& t1, const T2& t2, const T3& t3, const T4& t4)
	{
		if (msg_code == 0)
		{
			return;
		}
		if (socket_id == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);
		send_to_player["param3"] = ::common::ToString(t4);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(socket_id, m_send, common_msg_notify);
	}

	template< typename T1, typename T2, typename T3, typename T4, typename T5 >
	static void SendMsgCodeToPlayer(uint32_t socket_id, int32_t msg_code, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5)
	{
		if (msg_code == 0)
		{
			return;
		}
		if (socket_id == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);
		send_to_player["param3"] = ::common::ToString(t4);
		send_to_player["param4"] = ::common::ToString(t5);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().send_by_uid(socket_id, m_send, common_msg_notify);
	}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

    static void SendMsgCodeToAllPlayer( int32_t msg_code )
    {
		if (msg_code == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().broadcast_msg_to_client(m_send, common_msg_notify);
    }

    template< typename T1 >
    static void SendMsgCodeToAllPlayer( int32_t msg_code, const T1& t1 )
    {
		if (msg_code == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().broadcast_msg_to_client(m_send, common_msg_notify);
    }

    template< typename T1, typename T2 >
    static void SendMsgCodeToAllPlayer( int32_t msg_code, const T1& t1, const T2& t2 )
    {
		if (msg_code == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().broadcast_msg_to_client(m_send, common_msg_notify);
    }

    template< typename T1, typename T2, typename T3 >
    static void SendMsgCodeToAllPlayer( int32_t msg_code, const T1& t1, const T2& t2, const T3& t3 )
    {
		if (msg_code == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().broadcast_msg_to_client(m_send, common_msg_notify);
    }

    template< typename T1, typename T2, typename T3, typename T4 >
    static void SendMsgCodeToAllPlayer( int32_t msg_code, const T1& t1, const T2& t2, const T3& t3, const T4& t4 )
    {
		if (msg_code == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);
		send_to_player["param3"] = ::common::ToString(t4);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().broadcast_msg_to_client(m_send, common_msg_notify);
    }

    template< typename T1, typename T2, typename T3, typename T4, typename T5 >
    static void SendMsgCodeToAllPlayer( int32_t msg_code, const T1& t1, const T2& t2, const T3& t3, const T4& t4, const T5& t5 )
    {
		if (msg_code == 0)
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		send_to_player["param1"] = ::common::ToString(t2);
		send_to_player["param2"] = ::common::ToString(t3);
		send_to_player["param3"] = ::common::ToString(t4);
		send_to_player["param4"] = ::common::ToString(t5);

		std::string m_send = JsonWriter(send_to_player);
		GameServer::GetInstance().broadcast_msg_to_client(m_send, common_msg_notify);
    }

	////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

	static void SendMsgCodeToAllPlayer(std::string& msg)
	{
		GameServer::GetInstance().broadcast_msg_to_client(msg, common_msg_notify);
	}

	template< typename T1 >
	static void SendMsgCodeToTeam(CTeam& team, int32_t msg_code, const T1& t1)
	{
		if ( msg_code == 0 )
		{
			return;
		}
		Json::Value send_to_player;
		send_to_player["msgid"] = common_msg_notify;
		send_to_player["code"] = msg_code;
		send_to_player["param0"] = ::common::ToString(t1);
		team.BroadcastMessage(common_msg_notify, send_to_player);
	}
};

#endif

